from itertools import permutations
n = int(input())
template = "%5d"*n
for i in permutations(range(1,n+1)):
    print(template % i)